home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / MiniGames / BaseMiniGame.as
Text File  |  2013-04-24  |  4KB  |  161 lines

  1. class MiniGames.BaseMiniGame extends State
  2. {
  3.    static var sSTATE_HOWTOPLAY_IN = "HowToPlayIn";
  4.    static var sSTATE_HOWTOPLAY_IDLE = "HowToPlayIdle";
  5.    static var sSTATE_HOWTOPLAY_OUT = "HowToPlayOut";
  6.    static var sSTATE_MINIGAME = "MiniGame";
  7.    static var sSTATE_VICTORY = "Victory";
  8.    static var nSCORE_MAX = 1200;
  9.    static var nWAITING_TIME = 105;
  10.    function BaseMiniGame(_mcRef)
  11.    {
  12.       super(_mcRef);
  13.       this.bOver = false;
  14.    }
  15.    function initMiniGame()
  16.    {
  17.    }
  18.    function validateEndMiniGame()
  19.    {
  20.    }
  21.    function destroyMiniGame(_bQuitting)
  22.    {
  23.       if(_bQuitting == false || _bQuitting == undefined)
  24.       {
  25.          this.calculateScore();
  26.       }
  27.       this.cleanUp();
  28.    }
  29.    function calculateScore()
  30.    {
  31.    }
  32.    function addScoreFromTimeLeft(_nTimeMax, _nSecondsValue)
  33.    {
  34.       var _loc4_ = Math.round(_nTimeMax - this.nTime / Main.nFRAME_RATE);
  35.       if(_loc4_ < 0)
  36.       {
  37.          _loc4_ = 0;
  38.       }
  39.       _loc4_ *= _nSecondsValue;
  40.       if(_loc4_ > MiniGames.BaseMiniGame.nSCORE_MAX)
  41.       {
  42.          _loc4_ = MiniGames.BaseMiniGame.nSCORE_MAX;
  43.       }
  44.       CTRLGame.getRef().addToScore(_loc4_);
  45.    }
  46.    function isFinished()
  47.    {
  48.       return this.bOver;
  49.    }
  50.    function showInstructions()
  51.    {
  52.       this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IN);
  53.       Controller.getRef().getSounds().playSound("Minigame_HowToPlay_In",Controller.nSFX_VOLUME,1);
  54.    }
  55.    function doPause()
  56.    {
  57.       super.doPause();
  58.    }
  59.    function doUnPause()
  60.    {
  61.       super.doUnPause();
  62.       this.mcRef.stop();
  63.    }
  64.    function startGame()
  65.    {
  66.       this.clearSkipKeys();
  67.       this.setState(MiniGames.BaseMiniGame.sSTATE_MINIGAME);
  68.       CTRLGame.getRef().Screen.getInterface().unPauseTime();
  69.       this.initMiniGame();
  70.       this.nTime = 0;
  71.    }
  72.    function setVictory()
  73.    {
  74.       this.setState(MiniGames.BaseMiniGame.sSTATE_VICTORY);
  75.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  76.    }
  77.    function pressKey()
  78.    {
  79.       if(Key.getCode() != Key.UP && (Key.getCode() != Key.DOWN && (Key.getCode() != Key.LEFT && (Key.getCode() != Key.RIGHT && this.sState == MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IDLE))))
  80.       {
  81.          this.skipInstructions();
  82.       }
  83.    }
  84.    function pressMouseButton()
  85.    {
  86.       Controller.getRef().playClickSound();
  87.       this.skipInstructions();
  88.    }
  89.    function skipInstructions()
  90.    {
  91.       this.clearSkipKeys();
  92.       this.onOutInstructions();
  93.    }
  94.    function onOutInstructions()
  95.    {
  96.       this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_OUT);
  97.       Controller.getRef().getSounds().playSound("Minigame_HowToPlay_Out",Controller.nSFX_VOLUME,1);
  98.    }
  99.    function clearSkipKeys()
  100.    {
  101.       delete this.mcRef.mcState.btnSkip.onRelease;
  102.       delete this.mcRef.mcState.btnSkip2.onRelease;
  103.       delete this.mcRef.mcState.btnSkip2.onRollOver;
  104.       this.mcRef.mcState.btnSkip.onRelease = undefined;
  105.       this.mcRef.mcState.btnSkip2.onRelease = undefined;
  106.       this.mcRef.mcState.btnSkip2.onRollOver = undefined;
  107.       if(this.oListener != null)
  108.       {
  109.          Key.removeListener(this.oListener);
  110.          delete this.oListener;
  111.          this.oListener = null;
  112.       }
  113.    }
  114.    function initSkipKeys()
  115.    {
  116.       this.oListener = new Object();
  117.       this.oListener.onKeyDown = Delegate.create(this,this.pressKey);
  118.       Key.addListener(this.oListener);
  119.       this.mcRef.mcState.btnSkip.onRelease = Delegate.create(this,this.skipInstructions);
  120.       this.mcRef.mcState.btnSkip2.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
  121.       this.mcRef.mcState.btnSkip2.onRelease = Delegate.create(this,this.pressMouseButton);
  122.    }
  123.    function HowToPlayIn()
  124.    {
  125.       if(this.stateFinished())
  126.       {
  127.          this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IDLE);
  128.          this.initSkipKeys();
  129.       }
  130.    }
  131.    function HowToPlayIdle()
  132.    {
  133.       if(this.stateFinished())
  134.       {
  135.          this.onOutInstructions();
  136.       }
  137.    }
  138.    function HowToPlayOut()
  139.    {
  140.       if(this.stateFinished())
  141.       {
  142.          this.startGame();
  143.       }
  144.    }
  145.    function MiniGame()
  146.    {
  147.       if(!Controller.getRef().isPaused())
  148.       {
  149.          this.nTime = this.nTime + 1;
  150.          this.validateEndMiniGame();
  151.       }
  152.    }
  153.    function Victory()
  154.    {
  155.       if(this.stateFinished())
  156.       {
  157.          this.bOver = true;
  158.       }
  159.    }
  160. }
  161.